//
//  THJDJSelectView.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/9/14.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJDJSelectView.h"
#import <SDAutoLayout.h>
#import "THJSelectCell.h"

@implementation THJDJSelectView
{
    UITableView * _tableView;
//    NSInteger selectIndex;
}
-(instancetype)initWithFrame:(CGRect)frame{
    if(self = [super initWithFrame:frame]){
        [self setUI];
    }
    return self;
}
-(void)setUI{
    
//    UIView * bgView = [[UIView alloc] initWithFrame:CGRectMake(0,0,ScreenWidth,30)];
//    bgView.backgroundColor = SingleColor(whiteColor);
//    [self addSubview:bgView];
    
    
    self.backgroundColor = COLOR(0, 0, 0, 0.4);
//    selectIndex = 0;
    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, ScreenHeight*2/3-80, ScreenWidth, ScreenHeight/3)];
    self.tableview.delegate = self;
    self.tableview.tableFooterView = [UIView new];
    self.tableview.rowHeight = 44;
    [self.tableview registerNib:[UINib nibWithNibName:@"THJSelectCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    self.tableview.dataSource = self;
    [self addSubview:self.tableview];
    
    UIView * btnView = [[UIView alloc] initWithFrame:CGRectMake(0, ScreenHeight-80, ScreenWidth, 80)];
    btnView.backgroundColor = SingleColor(whiteColor);
    [self addSubview:btnView];
    
    UIButton * cancelBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:SingleColor(whiteColor) forState:UIControlStateNormal];
    [cancelBtn setBackgroundColor:COLOR(255, 97, 61, 1)];
    cancelBtn.layer.masksToBounds = YES;
    cancelBtn.layer.cornerRadius = 5;
    [cancelBtn addTarget:self action:@selector(removeView) forControlEvents:UIControlEventTouchUpInside];
    [btnView addSubview:cancelBtn];
    cancelBtn.sd_layout
    .topSpaceToView(btnView, 20)
    .leftSpaceToView(btnView, 15)
    .rightSpaceToView(btnView,15)
    .heightIs(40);
}
-(void)removeView{
    [self removeFromSuperview];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArr.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    THJSelectCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
//    if(selectIndex == indexPath.row){
//        cell.selectImg.image = kGetImage(@"对号");
//        cell.titleLab.textColor = MainColor;
//    }else{H
        cell.selectImg.image = nil;
//        cell.titleLab.textColor = SingleColor(grayColor);
//    }
    cell.titleLab.text = self.dataArr[indexPath.row][self.listKey];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
    
    

    NSDictionary * dic = self.dataArr[indexPath.row];
    [self.tableview reloadData];
    [self.delegate selectIndex:dic[@"id"] Info:dic Type:self.type];
    [self removeFromSuperview];
    
    
}
@end
